package com.wangshaoyu.music_player.controller;

import com.wangshaoyu.music_player.session_object.UserSO;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/studio/user")
public class StudioUserJsonController {
    @Data
    static class CurrentUserView {
        public UserSO currentUser;
    }

    @GetMapping("/current-user.json")
    public CurrentUserView getCurrentUser(HttpServletRequest req) {
        CurrentUserView view = new CurrentUserView();
        HttpSession session = req.getSession(false);
        if (session != null) {
            view.currentUser = (UserSO) session.getAttribute("currentUser");
        }

        return view;
    }
}
